#include "dyn_functor_maps1d_mandelbrotMap.h"

MandelbrotMap::MandelbrotMap(const double parameter, const int p)
    : Maps1D(p)
{
    setParameter(parameter);
}

double MandelbrotMap::iterate(double x, const int p)
{
    if (p==0)
        return x;

    for (int i=0;i<p;i++)
    {
        x = x*x+c;
    }
    return x;
}

double MandelbrotMap::jacobian(const double x, const int p)
{
    // We prepare a vector of size p
    // and setes its initial value.
    arma::vec jacVec(p);
    jacVec(0) = x;

    // We store the values of the iterates
    // and the jacobians at x and its (p-1) iterates.
    for (int i=1;i<p;i++)
    {
        jacVec(i) = iterate(jacVec(i-1),1);
    }

    return pow(2,p)*arma::prod(jacVec);
}
